package com.example.meetdroid;

import com.example.meetdroid.main.Globals;
import com.example.meetdroid.main.UserRequester;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity{
	
	private TextView txtUserName; 
	private Button cBtnAddContact;
	private Button cBtnTest;
	private Button cBtnOpenMap;
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainview);
        this.initComponents();
	}
	
	private void initComponents(){
		
		this.txtUserName = (TextView)findViewById(R.id.txtViewUserName);
		if( Globals.CurrentUser != null) this.txtUserName.setText(Globals.CurrentUser.getName());

		this.cBtnAddContact =(Button)findViewById(R.id.btnAddContact); 
		this.cBtnTest =(Button)findViewById(R.id.btnTest);
		this.cBtnOpenMap=(Button)findViewById(R.id.btnOpenMap);
		
		try{
			cBtnTest.setOnClickListener(new OnClickListener() {
			
				@Override
				public void onClick(View v) {
					try {
						Globals.Client.SendFriendRequest("exco","Ich will keine Werbung");
						//ShowAddUserActivity();	
					} catch (Exception e) {
						// TODO: handle exception
						Log.d("Meetup",e.getMessage());
					}
					
				}
				});
			
			this.cBtnOpenMap.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(Globals.AppContext, MapPane.class);
					startActivity(intent);
				}
				});
			
			cBtnAddContact.setOnClickListener(new OnClickListener() {
			
				@Override
				public void onClick(View v) {
					try {
						UserRequester _R = Globals.FriendRequests.get(0);
						Globals.Client.AcceptFriendRequest(_R.getID(), _R.getGUID(),"HUHUHU");
						//ShowAddUserActivity();	
					} catch (Exception e) {
						// TODO: handle exception
						Log.d("Meetup",e.getMessage());
					}
					
				}
				});
			
		}catch(Exception e){
			Log.d("Meetup",e.getMessage());
		}

	}
	private void ShowAddUserActivity(){
		try{
			
			Intent intent = new Intent(this, AddUserActivity.class);
			this.startActivity(intent);
			
		}catch(Exception e){
			Log.d("Meetup",e.getMessage());
		}
		
		

	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	    // Check which request we're responding to
	    if (requestCode == Globals.ACTIVITYREQUESTS.ADDCONTACT) {
	        // Make sure the request was successful
	        if (resultCode == Globals.ACTIVITYRESULTS.OK) {
	        	Globals.ShowToast(getApplicationContext(),"Anfrage versendet.");
	            // The user picked a contact.
	            // The Intent's data Uri identifies which contact was selected.

	            // Do something with the contact here (bigger example below)
	        }
	    }
	}
	 
}
